import React from 'react';
import { connect } from 'react-redux';

class Cart extends React.Component {
  // buy = (count) =>{
  //   store.dispatch({
  //     type: 'buy',
  //     payload: { count },
  //   })
  // }
  render() {
    return (
      <div>
       <div>我是购物车页面</div>
       <div>我的余额{this.props.money}</div>
        <div><button onClick={()=>this.props.buy(99)}>消费</button></div>
      </div>
    );
  }
}

const mapStateToProps = (state) => {
  return { money: state.money.money }
}
const mapDispatchToProps = (dispatch) => {
  return {
    buy: (count) => dispatch({ type: 'buy', payload: { count } }),
  }
}
export default connect(mapStateToProps, mapDispatchToProps)(Cart);